﻿using System;
using System.Linq.Expressions;

namespace CustomORM.Mapping
{
    public interface IMappingExpression
    {
        string ColumnName { get; }
        bool ForceDeleteMissedItems { get; set; }
        bool HasFieldConverter { get; set; }
        bool AssignedValueToBeUsed { get; set; }
        IFieldConverter FieldConverter { get; set; }
    }

    public class MappingExpression<T> : IMappingExpression
    {
        public MappingExpression(Expression<Func<T, object>> executionExpression, string columnName)
        {
            ExecExpression = executionExpression;
            FuncReady = executionExpression.Compile();
            ColumnName = columnName;
        }

        public Expression<Func<T, object>> ExecExpression { get; private set; }
        public Func<T, object> FuncReady { get; private set; }
        public string ColumnName { get; private set; }
        public bool ForceDeleteMissedItems { get; set; }
        public bool HasFieldConverter { get; set; }
        public bool AssignedValueToBeUsed { get; set; }
        public IFieldConverter FieldConverter { get; set; }

        public MappingExpression<T> DeleteMissedItems()
        {
            ForceDeleteMissedItems = true;
            return this;
        }

        public MappingExpression<T> AddConverter(IFieldConverter converter)
        {
            FieldConverter = converter;
            HasFieldConverter = true;
            return this;
        }

        public MappingExpression<T> UseAssignedValue()
        {
            AssignedValueToBeUsed = true;
            return this;
        }
    }

}